﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Bibylon.BehafX.StateMachine.concept
{
    /// <summary>
    /// Behavior Tree, [a.k.a Action Hierarchy Finite State Machine.
    /// </summary>
    internal abstract class tree // : node 
    {
        public tree(string name, string script)
        {
            Name = name;
            Root = null;
            QueryStatus = Status.Undefined;

            // Init the tree from the scripts
            // (void*)script;
        }

        /// <summary>
        /// Named-Symbol of the behavior tree
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// Root of the tree.
        /// </summary>
        public node Root { get; private set; }

        /// <summary>
        /// Running State of the tree
        /// </summary>
        public Status QueryStatus { get; private set; }

        /// <summary>
        /// User defined data to the tree
        /// </summary>
        public object userAny { get; set; }

        /// <summary>
        /// Simply run the behavior tree.
        /// </summary>
        public void Run(object agent)
        {
            Root.evaluate(agent, userAny);
        }

        /// <summary>
        /// Shutdown all nodes up to down .
        /// </summary>
        /// <param name="agent"></param>
        public void shutdown(object agent)
        {
            Root.shutdown(agent, true);
        }
    }
}
